package com.geccocrawler.gecco.demo.heilongjiang;

import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: weixiaohu
 * Date: 2019/6/3
 * Time: 15:05
 */
@PipelineName("regionProcessPipeline")
public class RegionProcessPipeline implements Pipeline<Region> {
    public static List<HttpRequest> regionRequests = new ArrayList<HttpRequest>();

    @Override
    public void process(Region region) {
        List<Option> options = region.getOptions();
        HttpRequest request = region.getRequest();
        options.forEach(option ->{
            String url = request.getUrl();
            url = StringUtils.replaceOnce(url, "id=" + region.getId(), "v1&id=" + option.getValue());
            regionRequests.add(request.subRequest(url));
        });
    }
}
